package com.example.app;

import java.util.HashSet;
import java.util.Set;

import net.sf.calibur.msgbuf.MessageBean;


public class HandlerContext {
	private Set<MessageBean> borrowedBeans = new HashSet<MessageBean>();
	
	public <T extends MessageBean> T getMessageBean(Class<T> clazz) {
		T mbean =  AppContext.getInstance().getMessageBeanFactory().borrowMessageBean(clazz);
		borrowedBeans.add(mbean);
		return mbean;
	}
	
	public void clear() {
		for (MessageBean mbean : borrowedBeans) {
			mbean.release();
		}
		
		borrowedBeans.clear();
	}
}